Uec3.PartUploadWindow = Ext.extend(Ext.app.Module, {
   	id: 'partUpload_operation',
   	permissionId:31,
    objsCollection:new Ext.util.MixedCollection(true),
	getObjByKey:function(key){
		return this.objsCollection.get(key);
	},
   	getPanel:function(params,scope) {
    var module=this;
   	var wMaskCol=new Ext.util.MixedCollection(false);
   	var windowLoadMask;
   	var ajax=getOwnerAjax();
   	var buttonAjax=new Ext.data.Connection();
   	Ext.util.Observable.capture(buttonAjax,function(e){
   		if(e=='beforerequest'){
   			Ext.MessageBox.show({
                title : "提示",
                msg : "加载中,请稍后.....",
                width:200,
                buttons: false,
                closable:false,
                wait:true,
                modal:false,
                minWidth: this.minProgressWidth
              
            });
   		}else if(e=='requestcomplete'){
   			Ext.MessageBox.hide();
   		}
   	});
	var initial=null;
	 //金额
	var amount=0;
	var initialItem_record = Ext.data.Record.create( [ {
		name : 'id',
		type : 'int',
		mapping : 'id'
	}, {
		name : 'nameEn',
		type : 'string',
		mapping : 'nameEn'
	}, {
		name : 'code',
		type : 'string',
		mapping : 'code'
	}, {
		name : 'name',
		type : 'string',
		mapping : 'name'
	}, {
		name : 'measurementUnit',
		type : 'string',
		mapping : 'measurementUnit'
	}, {
		name : 'brand',
		type : 'string',
		mapping : 'brand'
	}, {
		name : 'origin',
		type : 'string',
		mapping : 'origin'
	}, {
		name : 'carModel',
		type : 'string',
		mapping : 'carModel'
	}, {
		name : 'status',
		type : 'string',
		mapping : 'status'
	}, {
		name : 'errorMsg',
		type : 'string',
		mapping : 'errorMsg'
	}]);
/* store */

	
	var ds_measurementUnit_select = new Ext.data.JsonStore({
					url : Uec3.App.Constants.homeUrl + "/part/getUnitsForPage.do",
					totalProperty : "totalProperty",
					root : "root",
					fields : [{name : 'name'}]
		});


	var ds_initialItem = new Ext.data.Store( {
		proxy : new Ext.data.HttpProxy( {
			url : Uec3.App.Constants.homeUrl+'/partUpload/listWithComId.do',
			baseParams : {
			limit : 20
		    }
		}),
		remoteSort:true,
		autoLoad:true,
		reader : new Ext.data.JsonReader( {
			totalProperty : 'totalProperty',
			root : 'root'
		}, initialItem_record)
	});
	module.objsCollection.add("gridStore",ds_initialItem);
	var ds_initialItem_other = new Ext.data.Store( {
		proxy : new Ext.data.HttpProxy( {
			url : Uec3.App.Constants.homeUrl+'/partUpload/listWithComId.do'
		}),
		pruneModifiedRecords : true,
		remoteSort:true,
		paramNames : {
			start : "start",
			limit : "limit"
		},
		reader : new Ext.data.JsonReader( {
			totalProperty : 'totalProperty',
			root : 'root'
		}, initialItem_record),
		listeners:{
			"beforeload":function(store,options){
				store.baseParams.initialId=ds_initialItem.baseParams.initialId;
				Ext.MessageBox.show({
					title : "提示",
		            msg : "加载中,请稍后.....",
		            buttons: false,
		            closable:false,
		            width:200,
		            wait:true,
		            modal:true,
		            minWidth: this.minProgressWidth
				});
			},
			'load':function(store,records){
				var num=ds_initialItem.getRange().length;
				ds_initialItem.add(records);
				var sm=initialItem_grid.getSelectionModel();
				sm.selectRow(num);
				initialItem_grid.getView().focusRow(num); 
				Ext.MessageBox.hide();
			}
		}
	});
	var ds_code_select = new Ext.data.JsonStore({
		url:Uec3.App.Constants.homeUrl+"/part/queryPart!getPartByCodeImplicitExt.do",
	    root:'root',
	    totalProperty: "totalProperty", //总记录数
        fields:[{name:'code',type:'string'}]
	});
	/* store结束 */


	var store_ds = new Ext.data.JsonStore({
		url : Uec3.App.Constants.homeUrl+ '/store/base!query.do',
		root:'root',
		totalProperty: "totalProperty",
		fields:[
			{name : 'id',type:'int'},
			{name : 'name',type:'string'},
			{name : 'pyCode',type:'string'}
		]
	});

	
	var sourceComboBox=Uec3.App.dictionary.getCombo("part_source",{name:'source',hiddenName:"source",fieldLabel : '来源',listeners :{
					'select':autoFillDetailForm
				}});

	


	var cm_initialItem = new Ext.grid.ColumnModel([ new Ext.grid.RowNumberer(), 
	   new Ext.grid.CheckboxSelectionModel({singleSelect : false}),
		{
		header : '零件编码',
		width : 120,
		sortable : true,
		align:"right",
		dataIndex : 'code'
		},{
		header : '零件名称',
		width : 120,
		sortable : true,
		align:"left",
		dataIndex : 'name'
		},{
		header : '零件英文名称',
		width : 120,
		sortable : true,
		align:"left",
		dataIndex : 'nameEn'
		}, {
		header : '车型',
		width : 200,
		sortable : true,
		align:"left",
		dataIndex : 'carModel'
		}, {
		header : '单位',
		width : 95,
		sortable : true,
		align:"left",
		dataIndex : 'measurementUnit'
		}, {
		header : '品牌',
		width : 75,
		sortable : true,
		align:"left",
		dataIndex : 'brand'
		}, {
		header : '产地',
		width : 170,
		sortable : true,
		align:"left",
		dataIndex : 'origin'
		},{
		header : '状态',
		width : 120,
		sortable : true,
		align:"left",
		dataIndex : 'status',
		renderer : function(value){
			             var s="";
			              if(value=='0'){
			              	s="草稿";
			              }else if(value=='1'){
			              	s="已提交等待处理";
			              }else if(value=='2'){
			              	s="成功处理";
			              }else if(value=='3'){
			              	s="处理失败";
			              }
		                  return s;
		                  }
		},{
		header : '错误信息',
		width : 180,
		align:"left",
		sortable : true,
		dataIndex : 'errorMsg'
		}]);


	var initialItem_grid = getInitialItemGrid();
	function getInitialItemGrid(){
		return new Ext.grid.GridPanel({
			cm : cm_initialItem,
			store : ds_initialItem,
			columnLines :true,
			sm:new Ext.grid.CheckboxSelectionModel({singleSelect : false}),
			iconCls : 'icon-grid',
			loadMask : {
				msg : '数据加载中...'
			},
			stripeRows : true,
			autoScroll : true,
			height : 330,
			tbar : new Ext.app.ModuleToolbar(
					[
							'-',
							{
								text : '提交',
								handler : gridSubmit
							},'-',
							{
								text : '新增',
								iconCls : 'icon-add',
								itemId:'add',
								handler : gridAdd
							},
							'-',
							{
								text : '修改',
								itemId:'edit',
								iconCls : 'icon-edit',
								handler : gridEdit
							},
							'-',
							{
								text : '删除',
								itemId:'delete',
								iconCls : 'icon-del',
								handler :gridDelete
							},
							'-',
							{
								text : 'Excel上传',
								itemId:'upload',
								iconCls : 'icon-file_upload',
								handler : fileUpload
							},'-',
							{
								text : 'Excel模板下载',
								iconCls : 'icon-file_down',
								handler : fileDownload
							}
							 ],{permission:module.permissionId}),
			bbar : new Ext.PagingToolbar({
				pageSize : 20,
				store : ds_initialItem,
				displayInfo : true,
				style : 'align:center',
				displayMsg : '第 {0} - {1} 条  共 {2} 条',
				emptyMsg : "没有记录"
			})
		});
	}
	module.objsCollection.add("itemGrid",initialItem_grid);
	/* 文件导入 */
	var initialItem_form_file = new Ext.FormPanel({
		fileUpload : true,
		width : 300,
		frame : true,
		title : '文件上传(最大上传10M)',
		autoHeight : true,
		bodyStyle : 'padding: 10px 10px 0 10px;',
		labelWidth : 50,
		defaults : {
			anchor : '95%',
			allowBlank : false
		},
		items : [{
			xtype : 'fileuploadfield',
			emptyText : '请选择Excel文件',
			fieldLabel : '文件',
			name : 'excel',
			buttonText : '浏览',
			listeners : {
				'fileselected' : function(fb, v) {
					if (Ext.util.Format.lowercase(v).lastIndexOf(".xls") != -1) {

					} else {
						Ext.Msg.alert("错误", "请选择正确的Excel文件");
						initialItem_form_file.getForm().reset();
					}
				}
			}
		}],
		buttons : [{
			text : '上传',
			iconCls:'icon-save',
			handler : fileSave
		},{
			text : '重置',
			handler : function() {
				initialItem_form_file.getForm().reset();
			}
		}]
	});
	/*文件上传window组件*/
	var initialItem_win_file = new Ext.Window({
		layout : 'fit',
		width : 400,
		height : 'auto',
		manager:scope.app.getDesktop().windows,
		closeAction : 'hide',
		plain : true,
		modal : true,
		items : [ initialItem_form_file ]
	});
	/*明细弹出对话框panel*/
	var initialItem_form_add = new Ext.FormPanel({
		labelAlign : 'right',
		labelWidth : 80,
		bodyStyle : 'padding:5px',
		border : false,
		frame:true,
		fileUpload : true,
		baseCls : 'x-plain',
		defaultType : 'textfield',
		height : 'auto',
		defaults:{
			width : 250
		},
		xtype : "form",
		items : [
			{  
				allowBlank : false,
				blankText : '零件编码不能为空',
				name : 'code',
				fieldLabel:'零件编码(*)',  				
   				emptyText : '至少输入三位零件编码'
			    },{
				xtype:'combo',				    				
				allowBlank : false,
				blankText : '单位不能为空',
				name : 'measurementUnit',					
				fieldLabel:'单位(*)',
				valueField:'name',
	            displayField : 'name',
   	  			mode : 'remote',
   	  			queryParam :'queryParam',
   	  			queryDelay:500,
   	  			minChars :1,
   	  			store : ds_measurementUnit_select,  	  								 
   	  			pageSize:10,
	   			selectOnFocus : true,
	   			triggerAction : 'all',
	   			loadingText : '加载中...',	   				
	   			emptyText : '请输入至少1个字符',
	   			listWidth:270,
	   			focusOrder:1
		   }, {
				fieldLabel : '零件名称(*)',
				allowBlank : false,
				name : 'name'
			}, {
				fieldLabel : '英文名称(*)',
				allowBlank : false,
				name : 'nameEn'
			}, {
				fieldLabel : '车型',
				name : 'carModel'
			}, {
				fieldLabel : '品牌',
				name : 'brand'
			}, {
				fieldLabel : '产地',
				name : 'origin'
			},{
			xtype:'hidden',
			name:'id'
			}
		],
		buttons : [{
				text : '保存',
				iconCls:'icon-save',
				handler : itemSave
			}, {
				text : '关闭',
				iconCls:'icon-close',
				handler : itemClose
		    }],
		buttonAlign:'center'
		
	});

	this.objsCollection.add("itemForm",initialItem_form_add);
    var desktop = Uec3.App.getDesktop();
	var initialItem_win_add = desktop.createWindowNoTask(
		{
			layout:'fit',
		    width:430,
		    closeAction:'hide',
		    height:330,
		    title:"新增零件编码-ESC关闭",
			resizable :true,
			//manager:scope.app.getDesktop().windows,
			shadow : true,
			modal :true,
		    closable:true,
		    bodyStyle:'padding:5 5 5 5',
		    animCollapse:true,
			items : [ initialItem_form_add ]

	});
	this.objsCollection.add("itemWin",initialItem_win_add);

	/*整个页面的initialform对象*/
	var initialFormPanel = new Ext.FormPanel({
		labelAlign : 'right',
		//autoScroll: true,
		autoHeight:true,
		frame : true,
		labelWidth:60,
		defalutType:'textfield',
		items : [{
                    layout:'hbox',
                    layoutConfig:{align:'middle'},
                    items:[
                       {
		                xtype:'spacer',
                        flex:1
		               },{
                        xtype:'label',
                        text:'新零件编码',
                        style: 'font-size:24px'

                       },{
		                xtype:'spacer',
                        flex:1
		               },{
		                xtype:'spacer',
		                width:20,
                        flex:1
		               }
                    ]
                  },{
                    html:'<hr color="#888" />'
                  },{
				layout:'form',
				itemId:'maskTopField',
				defaults: {}
				
			}, initialItem_grid,{
			xtype : 'fieldset',
			border : false,
			layout : 'column',
			style:'padding:0px;margin:5px 0px 5px 0px'

		}]
	});
	

	
	/*grid方法*/
	/*增加*/
	function gridAdd() {
		if(initialItem_form_add.form.getEl()){
			initialItem_form_add.form.reset();
			initialItem_form_add.form.el.dom.reset();
		}else{
			initialItem_form_add.form.reset();
		}
		initialItem_win_add.isAdd=true;
		initialItem_win_add.setTitle("新增零件编码-ESC关闭");
		initialItem_win_add.show();
	}
	this.objsCollection.add('gridAdd',gridAdd);
	
	function gridEdit() {
		var record = initialItem_grid.getSelectionModel().getSelected();
		if (record) {
			initialItem_win_add.isAdd=false;
			initialItem_win_add.setTitle("编辑零件编码-ESC关闭");
			initialItem_form_add.getForm().loadRecord(record);
			initialItem_win_add.show();
		} else {
			Ext.MessageBox.alert("信息","请选择一行");
		}
	}
	
	function gridSubmit() {
		var records = initialItem_grid.getSelectionModel().getSelections();
		var len=records.length;
		if (len>0) {
			var idItem = [];
			for(var i=0;i<len;i++){
				idItem.push(records[i].data.id);
			}
			
			Ext.Ajax.request({
	           			url : Uec3.App.Constants.homeUrl+'/partUpload/submit.do',
	           			method :"post",
	           			params :{
						  ids : Ext.encode(idItem)
					     },
						waitMsg : '正在提交数据,请稍候...',
	          			success:function(response,options){
							ds_initialItem.reload();
							Ext.MessageBox.alert("提示","操作成功!");
							
	           			},
	           			failure:function(response,options){
	                		Ext.MessageBox.alert("提示","发生异常，请稍候处理!");    
	           			}
	       			});
			
		} else {
			Ext.MessageBox.alert("信息","请选择一行");
		}
	}
	this.objsCollection.add('gridEdit',gridEdit);
	
	function gridDelete() {
		var records = initialItem_grid.getSelectionModel().getSelections();
		var len=records.length;
		if (len>0) {
			var idItem = [];
			for(var i=0;i<len;i++){
				idItem.push(records[i].data.id);
			}
			
			Ext.Msg.confirm('信息','确定要删除所选记录',function(btn) {
			if (btn == 'yes') {
				initialItem_grid.loadMask.show();
				Ext.Ajax.request( {
					method : 'POST',
					params : {
						ids : Ext.encode(idItem)
					},
					url : Uec3.App.Constants.homeUrl+'/partUpload/deleteWithComId.do',
					success : function(response) {
						var result = Ext.decode(response.responseText);
						if(result.success){
							ds_initialItem.reload();
						}else{
							Ext.Msg.alert('信息',result.msg);
						}
						initialItem_grid.loadMask.hide();
					},
					failure : function() {
						Ext.Msg.alert('网络问题!');
						initialItem_grid.loadMask.hide();
					}
				});
			}
		});
			
		}else{
			Ext.Msg.alert('信息',"请选择一行");
			return false;
			
		}
	}
	
	
	function fileUpload() {
		initialItem_win_file.show();
		initialItem_form_file.getForm().reset();
	}
	

	function fileDownload() {
		if (!Ext.fly('test')){ 
			var frm = document.createElement('form'); 
			frm.id = 'test'; 
			frm.style.display = 'none'; 
			document.body.appendChild(frm); 
		} 
		Ext.Ajax.request({ 
			url:Uec3.App.Constants.homeUrl+"/partUpload/download.do",
			form: Ext.fly('test'), 
			method: 'POST',   
		    isUpload: true,
		    success:function(response){
		    	
		    }
		}); 
	}

	function fileSave(btn) {
		if(initialItem_form_file.getForm().isValid()) {
			initialItem_form_file.getForm().submit({
			url : Uec3.App.Constants.homeUrl+'/partUpload/readExcelData.do',
			method :"post",	
			waitMsg : '正在上传excel文件,请稍后',
			success : function(form,action){

  				var result=action.result;
				if(result.success){
					Ext.Msg.alert("返回信息",result.msg);
					if(result.OK=='ok'){
						ds_initialItem.reload();
					}
					
					
  				}else{
  					Ext.Msg.alert("返回信息",result.msg);
  				}
  				initialItem_win_file.hide();
		    	}
		 });
		}
	}
	function  itemSave(btn) {
		var frm = initialItem_form_add.form;
		
		
		if(!frm.isValid()){
			return false;
		}

		if(initialItem_win_add.isAdd){
				Ext.Ajax.request({
					waitMsg:'请稍后.....',
					waitTitle:'提示',
					url:Uec3.App.Constants.homeUrl+'/partUpload/newPartSave.do',
			        method :"post",	
			        params : {
						jsonData : Ext.util.JSON.encode(frm.getValues())
				    },
			        success:function(response,options){
			        	var result = Ext.decode(response.responseText);
			        	if(result.success){
			        		
			        		Ext.Msg.alert("信息",result.msg);
			        		initialItem_form_add.form.reset();
			        		ds_initialItem.reload(); 
			        	}else{
			        		
			        		Ext.Msg.alert("信息",result.msg);
			        	}
			        },
			      failure:function(form,action){
			          Ext.Msg.alert('提示','操作失败  ');
			      }
			});
		
			
		}else{
				Ext.Ajax.request({
					waitMsg:'请稍后.....',
					waitTitle:'提示',
					url:Uec3.App.Constants.homeUrl+'/partUpload/updatePartUpload.do',
			        method :"post",	
			        params : {
						jsonData : Ext.util.JSON.encode(frm.getValues())
				    },
			        success:function(response,options){
			        	var result = Ext.decode(response.responseText);
			        	if(result.success){
			        		
			        		Ext.Msg.alert("信息",result.msg);
			        		ds_initialItem.reload();
			        		initialItem_win_add.hide();
			        	}else{
			        		
			        		Ext.Msg.alert("信息",result.msg);
			        	}
			        	
			        },
			      failure:function(form,action){
			          Ext.Msg.alert('提示','操作失败  ');
			      }
			});
		
			
		}
		
	}
	module.objsCollection.add("itemSave",itemSave);
	function itemClose() {
		initialItem_win_add.hide();
	}
	module.objsCollection.add("itemClose",itemClose);
	var operation=function(btn){
		eval(btn.func+"(btn)");
	}
	
	/*新建单据*/
	function initialNew(btn){
		redirectUrl("partUpload_operation");
	}
	/*接手单据*/
    function initialRecieve(btn){
    	Ext.Msg.confirm("提示",((initial.currentorName==null||initial.currentorName=='')?"无人":initial.currentorName)+"在处理,确定要接手?",function(btn2){
			if(btn2=="yes"){
				formSubmit(btn.url,function(form,action){
					buttonAjaxRequest("currentorModify",false,function(result){
					Ext.Msg.alert("信息","接手成功");
					});
				});
			}
		});
	}
	/*释放单据*/
	function initialRelease(btn){
		var fn=function(form,action){
			initial.currentorName=null;
			buttonAjaxRequest("notCurModify",true,function(result){
				Ext.Msg.alert("信息","释放成功");
			});
		}
		formSubmit(btn.url,fn);
	}

	/*查看期初列表*/
	function initialView(btn){
		refreshInitialIndex();
		redirectUrl('partUpload_index');
	}
	/*后台ajax传递函数*/
	function formSubmit(url,fn,obj){
		var result;
		var params={
			waitMsg:'请稍后.....',
			waitTitle:'提示',
			url:Uec3.App.Constants.homeUrl+url,
	        method :"post",				
	        timeout:1800000,
	        success:function(form,action){
	      		result=action.result;
	      		if(result.success=='OK'){
		  			if(Ext.isFunction(fn))fn(form,action);
		  		}else{
		  			Ext.Msg.alert('信息',result.success); 
		  		}
	       	},
			failure:function(form,action){
	        	Ext.Msg.alert('提示','本地网络问题,请稍后连接!');
	      	}
		};
		if(obj)Ext.apply(params,obj);
		initialFormPanel.form.submit(params);
		return result;
	}
	/*保存*/
	function initialSave(btn){
		if(isItemGridValid()){
			var result=formSubmit(btn.url,function(form,action){
				buttonAjaxRequest("currentorModify",false,function(){
					Ext.Msg.alert('提示','保存成功 ');
				});				
			},getInitialFormPanelObj());
		}else{
			Ext.Msg.alert('提示','请至少加一条明细记录  ');
		}
	}
	/*提交*/
	function initialSubmit(btn){
		if(isItemGridValid()){
		 	initialFormPanel.form.submit({
				waitMsg:'请稍后.....',
				waitTitle:'提示',
				url:Uec3.App.Constants.homeUrl+'/initial/countErrors.do',
		        method :"post",					   
		        success:function(form,action){
			      	var result=action.result;
			      	if(result.success=='OK'){
			      		if(result.correctCount==0){
			      			Ext.Msg.show({
			      				title:'错误',
   								msg: '没用一条正确的数据,请重新修改再提交',
							   	buttons: Ext.Msg.OK,
							   	icon: Ext.MessageBox.ERROR
			      			});
			      			return;
			      		}else if(result.errorCount==0&&result.warnCount==0){
			      			formSubmit(btn.url,aftersubmitFunc,getInitialFormPanelObj());
			      		}else if(result.errorCount>0||result.warnCount>0){
					  		var str='';
					  		if(result.errorCount>0){
					  			str+=result.errorCount + '个零件错误.';
					  		}
					  		if(result.warnCount>0){
					  			str+=result.warnCount + ' 个零件警告.';
					  		}
					  		if(result.errorCount>0||result.warnCount>0){
					  			str+='确定要提交吗?'
					  		}
					  		Ext.Msg.show({
			      				title:'错误',
   								msg: str,
							   	buttons: Ext.Msg.YESNO,
							   	icon: Ext.MessageBox.WARNING,
								fn:function(btn2){
									if(btn2=="yes"){
										formSubmit(btn.url,aftersubmitFunc,getInitialFormPanelObj());
									}
								}
			      			});
			      		}
				  	}else{
				  		Ext.Msg.alert('信息',result.success); 
				    }
		      	},
		        failure:function(form,action){
		        	Ext.Msg.alert('提示','提交失败');
		      	}
			});
		}else{
			Ext.Msg.alert('提示','请至少加一条明细记录');
		}
	}
	function getInitialFormPanelObj(){
		return {params:{data:Ext.encode(encodeFilte(initialFormPanel.getForm().getValues()))}};
	}
	/*提交后的操作*/
	function aftersubmitFunc(form,action){
		buttonAjaxRequest("formal",true,function(){
		refreshInitialIndex();
		var result=action.result;
		if(result.errorInitial){
			Ext.MessageBox.show({title:"信息",msg:"错误期初零件明细在单据号为"+result.errorInitial.code+"里",buttons:Ext.MessageBox.OK,fn:function(){
				redirectUrl("partUpload_operation",{id:result.errorInitial.id,winId:result.errorInitial.id});
			}});
		}else if(result.initial){
			initialFormPanel.getForm().setValues(result.initial);
		}
		});
		
	}
	/*删除*/
	function initialDelete(btn){
		Ext.Msg.confirm("提示","确定删除此期初单",function(btn2){
			if(btn2=="yes"){
			    formSubmit(btn.url,function(){
			    	redirectUrl('partUpload_index');
			    	refreshInitialIndex();
			    });
			}
		});
	}
	/*打印*/
	function initialPrint(){
		
	}
	/*返回*/
	function initialClose(){
		module.getObjByKey("win").close();
	}
	
	function isMark(isMark){
		var topToolbar=initialItem_grid.getTopToolbar();
		topToolbar.getComponent('add').enable();
		topToolbar.getComponent('edit').enable();
		topToolbar.getComponent('delete').enable();
		topToolbar.getComponent('upload').enable();
		if(isMark==true){
			topToolbar.getComponent('add').disable();
			topToolbar.getComponent('edit').disable();
			topToolbar.getComponent('delete').disable();
			topToolbar.getComponent('upload').disable();
		}
	}
	/*计算金额*/
	function calAmount(num){
		amount+=num;
    	initialFormPanel.getForm().setValues({'amount':amount})
	}

	
	function setEnableField(){
		initialItem_form_add.form.findField("code").enable();
		initialItem_form_add.form.findField("source").enable();
	}
	function setDisableField(){
		initialItem_form_add.form.findField("code").disable();
		initialItem_form_add.form.findField("source").disable();
	}
    function autoFillDetailForm(){
		var source = this.getValue();
		var code = initialItem_form_add.form.findField("code").getValue();
		if(!code)return;
	 	Ext.Ajax.request({
	    url :Uec3.App.Constants.homeUrl+"/part/getPartWithCodeAndSource.do",
	    params :{queryParam:Ext.encode({code:code,source:source})},
	    method :"post",
	    success:function(response,options){
		      var resp = Ext.decode(response.responseText);
	          if(resp.success){
	          	 Ext.MessageBox.alert("提示","零件编码已存在");
	          }else{
	          	
	          	
	          }
	    },
	    failure:function(response,options){
	          Ext.MessageBox.alert("提示","数据加载异常");
	        }
	 	});	    		  
    }
 	     
    function winShowOptions(){
    	windowLoadMask=new Ext.LoadMask(initialFormPanel.ownerCt.id);
   			 windowLoadMask.show();

   			 if(params&&params.id){
	 			initialFormPanel.getForm().load({
	   				url:Uec3.App.Constants.homeUrl+'/initial/getInitialById.do',
	   				params:{id:params.id},
	   				success:function(form,action){
	   					isMaskWindow("initialFormPanel");
	   					createInitialRet(action.result.data)
	   					var userId=action.result.userId;
	   					if(initial.status==0){
		   					if(initial.currentorId==userId){
		   						buttonAjaxRequest("currentorModify",false);
		   					}else{
		   						buttonAjaxRequest("notCurModify",true);
		   					}
	   					}else if(initial.status==1){
	   						buttonAjaxRequest("formal",true);
	   					}
	   					
		   				ds_initialItem.load();    // 加载initialItem表格数据  					
	   				}
		   		});//主表form加载
				
   			 }else{
   			 	isMaskWindow("initialFormPanel");
   			 	buttonAjaxRequest("new",false);
   			 }
    }
    module.objsCollection.add("winShowOptions",winShowOptions);
    
    function isMaskWindow(obj){
    	wMaskCol.add({id:obj});
    	if(windowLoadMask&&wMaskCol.getCount()==2){
    		windowLoadMask.hide();
    		wMaskCol.clear();
    	}
    }
    function redirectUrl(id,params){
    	var desktop =Uec3.App.getDesktop();   
		desktop.launchWindowByParam(id,params); 
		
    }
   	function isItemGridValid(){
   		var obj=initialFormPanel.form.getValues();
   		if(obj.id){
   			return true;
   		}else{
   			if(initialItem_grid.getStore().getCount()>0){
   				return true;
   			}
   		}
   		return false;
   	}
   	function refreshInitialIndex(){
		var window =Uec3.App.getDesktop().getWindowByUecId("partUpload_index");   
		if(window){
			var store=window.moduleObj.getObjByKey("store");
			store.reload();
		}   		
   	}
   	//按钮加载
   	function buttonAjaxRequest(typeId,mark,fn){

		 		isMaskWindow("buttons");
		 		
		 		//是否遮罩
   				isMark(mark);
   				initialFormPanel.ownerCt.doLayout();

		
   	}
   	
   	function createInitialRet(initialT){
   		initial=initialT;
   		ds_initialItem.baseParams={initialId:initial.id};
		initialFormPanel.getForm().setValues(initial);
		var desktop =Uec3.App.getDesktop();   
		desktop.changeWindowUecId("partUpload_operation","partUpload_operation_"+initial.id);   
		changeTaskButtonText(initial.code);
   	}
	function changeTaskButtonText(id){
		var win=module.getObjByKey("win");
		win.taskButton.setText("期初单:"+id);
	}   	
   	return initialFormPanel;
   },
    initEvents:function(){
   	var module=this;
   	var itemWin=module.getObjByKey("itemWin");
   	//itemWin.on('show',formBingingKeys,module,{single:true});
	
	//var gridKeyMap=winBingingKeys(module.getObjByKey("itemWin"),module.objsCollection);
	
	//module.getObjByKey("win").on('show',module.getObjByKey("winShowOptions"),this,{single:true});
	
   },
   createWindow : function(params,fn){
   	  var windowId='partUpload_operation';
   	  if(params&&params.winId){
   	  	windowId+="_"+params.winId;
   	  }
      var desktop = Uec3.App.getDesktop();
      var win = desktop.getWindowByUecId(windowId);
      var module=this;
      if(!win){
         win = desktop.createWindow({
         	uecId:windowId,
            title: '新增零件编码信息',
            width: document.body.clientWidth*0.9,
           	height: document.body.clientHeight*0.9,
            iconCls: 'acc-icon',
            constrainHeader: true,
            maximizable: true,
            layout: "fit",   
            items:[this.getPanel(params,this)],
            listeners:{
            	'resize':function(win,width,height){
            		var top=this.items.get(0).items.first();
            		var grid=this.items.get(0).items.get(3);
            		var winMinWidth=1000;
            		var winMinHeight=550;
            		if(width<winMinWidth||height<winMinHeight){
            			win.setWidth(winMinWidth);
            			win.setHeight(winMinHeight);
            			grid.setHeight(winMinHeight-100);
            		}else{
            			grid.setHeight(height-100);
            			
            		}
            	}
            }
         });     
      } 
      module.objsCollection.add("win",win);
      module.initEvents();
      if(Ext.isFunction(fn))fn();
      win.show();
   }
	});